function request(method, url, data = null) {
    return new Promise((resolve, reject) => {
      // 1.创建ajax对象
      let ajax = new XMLHttpRequest();
      // 2.open()打开 如果是get要考虑是否地址栏传参，post没有
      url = method == "get" && data != null ? url + "?" + data : url;
      ajax.open(method, url, true);
      // 3.post有,get没有
      if (method == "post")
        ajax.setRequestHeader(
          "content-type",
          "application/x-www-form-urlencoded"
        );
      // 4.send()发送请求 post有参数，get无参数
      ajax.send(method == "get" ? "" : data);
      // 5.监听 该监听函数会触发多次，跟随ajax的请求状态在不断地触发监听知道readyState=4为止
      ajax.onreadystatechange = function () {
        if (ajax.status == 200 && ajax.readyState == 4) {
          // 返回成功
          resolve(JSON.parse(ajax.response));
        }
      };
    });
  }
  